package entity;

import org.lwjgl.opengl.GL11;

public class Camera extends GameObject{
/*
 * move forward, back, left, and right inspired from the fps tutorial at
 * http://www.lloydgoodall.com/tutorials/first-person-camera-control-with-lwjgl/
 * by Lloyd
 */
	
	
public Camera(String name, float height, float radius, float mass)
{
	super(name,height,radius,mass);
}

/*public Camera(float posX ,float posY,float posZ,float rotX,float rotY,float rotZ)
{
this.setPos(new float[]{posX,posY,posZ});
this.setRot(new float[]{rotX,rotY,rotZ});
	
}
*/

public void turnRight()
{
	this.setRotY(this.getRotY()+1.0f);
}

public void turnUp()
{
	this.setRotX(this.getRotX()+1.0f);
	
	
}
public void turnDown()
{
	this.setRotX(this.getRotX()-1.0f);
}

public void turnLeft()
{
	this.setRotY(this.getRotY()-1.0f);
}

public void moveForward(float distance)
{
	float tempX=this.getPosX();
	float tempZ=this.getPosZ();
	float y= this.getRotY();
	float yRad=(float)Math.sin(Math.toRadians(y));
	
	tempX-= distance*yRad;
	yRad=(float)Math.cos(Math.toRadians(y));
	tempZ+= distance*yRad;
	
	this.setPosX(tempX);
	this.setPosZ(tempZ);
	
}
public void moveBack(float distance)
{
	float tempX=this.getPosX();
	float tempZ=this.getPosZ();
	float y= this.getRotY();
	float yRad=(float)Math.sin(Math.toRadians(y));
	
	tempX+= distance*yRad;
	yRad=(float)Math.cos(Math.toRadians(y));
	tempZ-= distance*yRad;
	
	this.setPosX(tempX);
	this.setPosZ(tempZ);
}

public void moveLeft(float distance)
{
	float tempX=this.getPosX();
	float tempZ=this.getPosZ();
	float y= this.getRotY()-90;
	float yRad=(float)Math.sin(Math.toRadians(y));
	
	tempX-= distance*yRad;
	yRad=(float)Math.cos(Math.toRadians(y));
	tempZ+= distance*yRad;
	
	this.setPosX(tempX);
	this.setPosZ(tempZ);
}
public void moveRight(float distance)
{
	float tempX=this.getPosX();
	float tempZ=this.getPosZ();
	float y= this.getRotY()+90;
	float yRad=(float)Math.sin(Math.toRadians(y));
	
	tempX-= distance*yRad;
	yRad=(float)Math.cos(Math.toRadians(y));
	tempZ+= distance*yRad;
	
	this.setPosX(tempX);
	this.setPosZ(tempZ);
}
public void moveUp(float distance)
{
	float tempY= this.getPosY();
	tempY-=distance;
	this.setPosY(tempY);
}

public void moveDown(float distance)
{
	float tempY= this.getPosY();
	tempY+=distance;
	this.setPosY(tempY);
}


public void lookAt()
{
	GL11.glTranslatef(0, 0, 0);
	GL11.glRotatef(getRot()[0], 1, 0, 0);
    GL11.glRotatef(getRot()[1], 0, 1, 0);
    GL11.glRotatef(getRot()[2], 0, 0, 1);
    GL11.glTranslatef(getPosX(), getPosY(), getPosZ());
}



}
